package bb.lanxing.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Bundle;

import bb.lanxing.R;
import bb.lanxing.util.ui.StatusBarUtil;

public class LushuStyleUtils {
    public static void installStyle(Intent intent, int style) {
    }

    public static int resolveStyle(Context activity) {
        Resources.Theme theme = activity.getTheme();
        if (theme == null) {
            return 0;
        }
        TypedArray obtainStyledAttributes = theme.obtainStyledAttributes(R.styleable.RouteBookStyle);
        int i = obtainStyledAttributes.getInt(R.styleable.RouteBookStyle_styleRouteBookStyleType, 0);
        obtainStyledAttributes.recycle();
        return i;
    }

    public static void recreate(Activity activity, Bundle arguments) {
        Intent intent = new Intent(activity, activity.getClass());
        if (arguments != null) {
            intent.putExtras(arguments);
        }
        activity.startActivity(intent);
        activity.finish();
        activity.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    }

    public static int applyTheme(Activity activity) {
        return applyTheme(activity, activity.getIntent().getIntExtra("route_book_style", 0));
    }

    public static boolean isFromApplyTheme(Activity activity) {
        return activity.getIntent().getBooleanExtra("is_from_apply_theme", false);
    }

    public static boolean shouldApplyTheme(Activity activity, int newStyle) {
        return resolveStyle(activity) != newStyle;
    }

    public static void applyThemeAndRestart(Activity activity, int newStyle, Bundle arguments) {
        if (arguments == null) {
            arguments = new Bundle();
        }
        arguments.putInt("route_book_style", newStyle);
        arguments.putBoolean("is_from_apply_theme", true);
        recreate(activity, arguments);
    }

    public static int applyTheme(Activity activity, int style) {
        int i = style != 1 ? R.style.AppTheme_LightToolBar_RouteBook_Default
                : R.style.AppTheme_LightToolBar_RouteBook_Immersive_TourDeFrance;
        activity.setTheme(i);
        TypedArray obtainStyledAttributes = activity.getTheme().obtainStyledAttributes(R.styleable.RouteBookStyle);
        boolean z = obtainStyledAttributes.getBoolean(R.styleable.RouteBookStyle_styleRouteBookLightStatusBar, false);
        obtainStyledAttributes.recycle();
        StatusBarUtil.darkMode(activity, !z);
        return i;
    }
}
